
package com.akupilih.app.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.akupilih.app.BuildConfig;

public class Utils {

    private static final String PREF_NAME = "aku_pilih";
    public static final String PREF_ISLOGIN = "islogin";
    public static final String PREF_FB_ID = "fb_id";
    public static final String PREF_USERNAME = "username";
    private static SharedPreferences sp;

    /**
     * Debugging method
     * 
     * @param tag TAG
     * @param msg Message out
     */
    public static void TRACE(String tag, String msg) {
        if (BuildConfig.DEBUG)
            Log.d(tag, msg);
    }

    public static void setDataIntTOSP(Context context, String to, int data) {
        Utils.TRACE("Utils", "setDataIntTOSP: " + data);
        sp = context.getSharedPreferences(PREF_NAME, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(to, data);
        editor.commit();
    }

    public static int getDataIntFromSP(Context context, String from) {
        sp = context.getSharedPreferences(PREF_NAME, 0);
        return sp.getInt(from, 0);
    }

    public static void setDataBooleanToSP(Context context, String to, boolean
            data) {
        Utils.TRACE("Utils", "setDataBooleanToSP: " + data);
        sp = context.getSharedPreferences(PREF_NAME, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(to, data);
        editor.commit();
    }

    public static boolean getDataBooleanFromSP(Context context, String from)
    {
        sp = context.getSharedPreferences(PREF_NAME, 0);
        return sp.getBoolean(from, false);
    }

    public static void setDataStringToSP(Context context, String to, String
            data) {
        Utils.TRACE("Utils", "setDataStringToSP: " + data);
        sp = context.getSharedPreferences(PREF_NAME, 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(to, data);
        editor.commit();
    }

    public static String getDataStringFromSP(Context context, String from) {
        sp = context.getSharedPreferences(PREF_NAME, 0);
        return sp.getString(from, "");
    }
}
